/**
 *	@class			Jx.data.Manager
 *	@description	manages models, records, and datasources
 */
Jx.declare('Jx.data.Manager', {

	$singleton: true,

	$extend: 'Jx.Base',

	$requires: [

		'Jx.lib.Hash',

		'Jx.data.Collection'

	],

	$actions: [

		'registerModel',

		'refreshTable',

		'select'

	],

	tables: undefined,

	dataSources: undefined,

	constructor: function(){

		this.tables = Jx.instantiate('Jx.lib.Hash');

		this.dataSources = Jx.instantiate('Jx.lib.Hash');

		this.$super(arguments);

	},

	onRegisterModel: function(operation, modelName){

		var Model = modelName;

		if (Jx.isFunction(modelName)){

			modelName = modelName.$name;

		} else {

			Model = Jx.getConstructor(modelName);

		}

		this.tables.set(modelName,

			Jx.instantiate('Jx.data.Table', [ modelName ])

		);

		//-- register dataSource
		var Prototype = Model.prototype,

			dsn = Prototype.dataSource;

		if (Jx.isString(dsn, true)){

			this.dataSources.set(

				dsn,

				Jx.instantiate('Jx.data.Source', [ dsn ])

			);
		}

	},

	onRefreshTable: function(operation){

		var rows = operation.table;

		//-- refresh data from a resource

	},

	onSelect: function(operation, table){

		var options = operation.options;


	},

	allowRegisterModel: function(operation, modelName){

		return Jx.isClass(modelName, 'Jx.data.Model');

	},

	allowRefreshTable: function(operation, tableName){

		return !!(operation.table = this.tables.get(tableName));

	},

	allowSelect: function(operation, table, options){

		if (!Jx.isObject(options)){

			options = {};

		}

		operation.options = options;

		return this.table.isSet(table);

	}


});
